package es.ucm.is.www.GUI.client.map;

/**
 * 
 */

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;

import es.ucm.is.www.GUI.client.city.CityConstructor;
import es.ucm.is.www.GUI.client.img.ImagenesCity;

/**
 * <p>Title: PopUpDescCell.java </p>
 *
 * <p>Description: Panel emergente con informacion de la casilla de mapa</p>
 *
 * <p>Copyright: Fernando Burillo</p>
 *
 * @author Fernando Burillo
 * @version 1.0
 * @see
 */
public class PopUpDescCell extends PopupPanel implements MouseListener, ClickListener{
	
	private VerticalPanel description;
	
	private Label cellType;
	
	private HorizontalPanel food;
	private HorizontalPanel mineral;
	private HorizontalPanel uranio;
	private HorizontalPanel money;
	private HorizontalPanel oil;
	private Label defMod;
	private Label speedMod;
	private Button createCity;
	/**
	 * Casilla sobre la que se muestra la informacion.
	 */
	private Casilla cas;
	private ImagenesCity imgs;
	
	/**
	 * Constructora de la clase
	 * @param celdaPinchada: celda en la que se ha pulsado
	 */
	public PopUpDescCell(final Casilla cas){
		super(true);
		this.setAnimationEnabled(true);
		description = new VerticalPanel();
		
		switch (cas.getTipo()){
			case Mapa.ID_DESERT:	cellType = new Label("Casilla de desierto");
									break;
			case Mapa.ID_MOUNTAIN:	cellType = new HTML("Casilla de monta&ntilde;a");
									break;
			case Mapa.ID_OCEAN:		cellType = new Label("Casilla de oceano");
									break;
			case Mapa.ID_PLAIN:		cellType = new Label("Casilla de llanura");
									break;
			case Mapa.ID_PRAIRIE:   cellType = new Label("Casilla de pradera");
									break;
			default:	cellType = new Label();
		}
		
		cellType.setStyleName("titulo");
		
		this.cas = cas;
		
		Label foodProd = new Label("Comida: " + cas.getTerrain().getFoodProd());
		Image comida = new Image();
		imgs = GWT.create(ImagenesCity.class);
		AbstractImagePrototype imagen1 = imgs.panMini();
		imagen1.applyTo(comida);
		food = new HorizontalPanel();
		food.add(comida);
		food.add(foodProd);
		
		Label mineralProd = new Label("Minerales: " + cas.getTerrain().getMineralProd());
		Image piedra = new Image();
		imagen1 = imgs.mineralMini();
		imagen1.applyTo(piedra);
		mineral = new HorizontalPanel();
		mineral.add(piedra);
		mineral.add(mineralProd);
		
		Label uranioProd = new Label("Uranio: " + cas.getTerrain().getUraniumProd());
		Image nuclear = new Image();
		imagen1 = imgs.uranioMini();
		imagen1.applyTo(nuclear);
		uranio = new HorizontalPanel();
		uranio.add(nuclear);
		uranio.add(uranioProd);
		
		Label moneyProd = new Label("Dinero: " + cas.getTerrain().getMoneyProd());
		Image billetes = new Image();
		imagen1 = imgs.oroMini();
		imagen1.applyTo(billetes);
		money = new HorizontalPanel();
		money.add(billetes);
		money.add(moneyProd);
		
		Label oilProd = new Label("Petroleo: " + cas.getTerrain().getOilProd());
		Image petroleo = new Image();
		imagen1 = imgs.petroleoMini();
		imagen1.applyTo(petroleo);
		oil = new HorizontalPanel();
		oil.add(petroleo);
		oil.add(oilProd);
		
		defMod = new Label ("Modificador defensa: x" + cas.getTerrain().getDefenceMod());
		speedMod = new Label ("Modificador velocidad: x" + cas.getTerrain().getSpeedMod());

		this.createCity = new Button("Crear ciudad", this) ;
			
		
		description.add(cellType);
		
		description.add(food);
		description.add(mineral);
		description.add(uranio);
		description.add(money);
		description.add(oil);
		description.add(defMod);
		description.add(speedMod);
		
		FocusPanel p = new FocusPanel();
		p.add(description);
		p.addMouseListener(this);
		
		VerticalPanel v = new VerticalPanel();
		v.add(p);
		
		if (cas.getTipo() != Mapa.ID_OCEAN)
			v.add(createCity);
		
		
		this.setWidget(v);
	}

	public void onMouseDown(Widget sender, int x, int y) {
		this.hide();
	}

	public void onMouseEnter(Widget sender) {

	}

	public void onMouseLeave(Widget sender) {
		
	}

	public void onMouseMove(Widget sender, int x, int y) {

	}

	public void onMouseUp(Widget sender, int x, int y) {

	}

	public void onClick(Widget sender) {
		PanelConstructionCity panel = new PanelConstructionCity(cas);
		panel.center();
		panel.show();
		this.hide();
		
	}
	
}
